// 	ID : pallab81
// 	PROG : 497
// 	LANG : C++
// 	2011-08-24-23.33.11 Wednesday
//
// 	"I have not failed, I have just found 10000 ways that won't work.
//


#include <iostream>
#include <algorithm>
#include <vector>
#include <sstream>
#include <fstream>
#include <string>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <functional>
#include <bitset>

#include <ctime>
#include <cassert>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <climits>
#include <cstring>

using namespace std;

#define CI( x ) scanf("%d",&x)
#define CL( x ) scanf("%lld",&x)
#define CD( x ) scanf("%lf",&x )
#define fo(i,ed) for(int i = 0 ; i < ed ; ++i )
#define foit(i, x) for (typeof((x).begin()) i = (x).begin(); i != (x).end(); i++)
#define bip system("pause")
#define Int long long
#define pb push_back
#define SZ(X) (int)(X).size()
#define LN(X) (int)(X).length()
#define mk make_pair
#define f first
#define s second
#define SET( ARRAY , VALUE ) memset( ARRAY , VALUE , sizeof(ARRAY) )

inline void wait( double seconds ){
    double endtime = clock() + ( seconds*CLOCKS_PER_SEC );
    while( clock() < endtime ){;}
}
inline int toI(string ss){
    int d;
    sscanf(ss.c_str(),"%d",&d);
return d;
}
string feed;
string line;
int cases;
vector< int > h;
inline void find_lis(vector<int> &a, vector<int> &b){
    vector<int> p(SZ(a));
    int n = SZ(a);
    int u,v;

    if( n < 1 )return ;
    b.push_back( (int)0 );

    for(int i=1; i<n; ++i){
        if( a[ b.back() ] < a[i] ){
            p[i] = b.back();
            b.push_back( i );
            continue;
        }
        for(u=0,v=SZ(b)-1; u < v ; ){
            int c = (u+v)/2;
            if( a[ b[c] ] < a[i] ){
                u = c+1;
            }
            else{
                v = c;
            }
        }
        if( a[i] < a[ b[u] ] ){
            if( u > 0 ){
                p[i]=b[u-1];
            }
            b[u]=i;
        }
    }

    for(u=SZ(b),v=b.back(); u--; v=p[v] ){
        b[u]=v;
    }
}
inline void Proc(){
    vector< int > b;
    find_lis(h,b);
    int N = SZ(b);
    printf("%sMax hits: %d\n",feed.c_str(),N);
    for(int i=0;i<N;++i){
        printf("%d\n",h[ b[i] ]);
    }
    feed="\n";
}

int main(){
//    #ifndef ONLINE_JUDGE
//        freopen("in.txt","rt",stdin);
//    #endif
    feed="";
    getline(cin,line);
    cases = toI(line);
    getline(cin,line);
    while( cases-- ){
        h.clear();
            while(getline(cin,line)){
                if( LN(line)<1 )break;
                h.pb( toI(line) );
            }
        Proc();
    }

return 0;
}
